import src.Base.ErrorLog;
import src.Lexer;
import src.LlvmGeneratror;
import src.Parse;
import src.Vistor;

import java.io.*;

public class Compiler {
    public static void main(String[] args) {
        String path = "testfile.txt";
        String outPutPath = "output.txt";
        File file = new File(path);
        File outPutFile = new File(outPutPath);
        if(outPutFile.exists()){
            outPutFile.delete();
        }
        FileReader fileReader = null;
        try {
            fileReader = new FileReader(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        BufferedReader reader = new BufferedReader(fileReader);
        Lexer lexer = new Lexer();
        String s = "len!=0";
        int line = 1;
        try{
            while ((s = reader.readLine()) != null){
                lexer.getOneWord(s, line);
                line++;
            }
        }catch (IOException e){
            e.printStackTrace();
        }
        Parse parse = new Parse(lexer.getWordArrayList());
        parse.analyze();
        parse.writeRes();//parse.printRes();
        Vistor vistor = new Vistor(parse.getHead());
        vistor.createSymbolTable();
        ErrorLog.instance.writeErrors();
        LlvmGeneratror llvmGeneratror = new LlvmGeneratror(parse.getHead());
        llvmGeneratror.generate();

    }
}
